package risk.control.project.utils.vaild;

import java.util.regex.Pattern;

public class PasswordValidator {

    /**
     * 验证密码是否符合要求
     *
     * @param password 要验证的密码字符串
     * @return 验证结果对象
     */
    public static ValidationResult validatePassword(String password) {
        if (password == null || password.length() < 6) {
            return new ValidationResult(false, "密码长度至少为6个字符");
        }

        // 定义允许的字符正则表达式
        Pattern pattern = Pattern.compile("^[1-9a-zA-Z@#$%^&*]+$");
        if (!pattern.matcher(password).matches()) {
            return new ValidationResult(false, "密码只能包含1-9数字、字母和@#\\$%^&*符号");
        }

        return new ValidationResult(true, "密码有效");
    }

    // 验证结果封装类
    public static class ValidationResult {
        public final boolean isValid;
        public final String message;

        public ValidationResult(boolean isValid, String message) {
            this.isValid = isValid;
            this.message = message;
        }
    }

}
